package o;

import android.text.TextUtils;
import com.huawei.appgallery.packagemanager.api.bean.ManagerTask;
import java.io.File;
import o.cof.a;
import o.cof.d;

public class dst {
    protected void ॱ() {
        eto.ˋ().ˎ(ContentManager.getInstant().getContext());
        if (cep.ˏ()) {
            Logger.ˎ("RecoveryPackageTask", "begin recoveryTask");
            fhz ˋ = fho.ˏ().ˋ("PackageManager");
            if (ˋ != null) {
                cob o_cob = (cob) ˋ.ॱ(cob.class);
                cnw o_cnw = (cnw) ˋ.ॱ(cnw.class);
                if (o_cob != null && o_cnw != null) {
                    for (ManagerTask managerTask : o_cob.ˎ(ContentManager.getInstant().getContext())) {
                        if (managerTask.processType == cod.INSTALL_EXISTING_PKG || managerTask.processType == cod.INSTALL) {
                            ˎ(o_cnw, managerTask);
                        } else if (managerTask.processType == cod.UNINSTALL) {
                            Logger.ˋ("RecoveryPackageTask", "find uninstall task,current state:" + ((cdg) cdb.ॱ(cdg.class)).ॱॱ(managerTask.packageName));
                        }
                        o_cob.ˋ(ContentManager.getInstant().getContext(), managerTask.taskId);
                    }
                }
            }
        }
    }

    private void ˎ(cnw o_cnw, ManagerTask managerTask) {
        if (managerTask.apkInfos != null && !managerTask.apkInfos.isEmpty()) {
            if (managerTask.status != cnz.INSTALLING && managerTask.status != cnz.WAIT_INSTALL) {
                return;
            }
            if (managerTask.mode == 1) {
                ॱ(o_cnw, managerTask);
            } else if (managerTask.mode == 2) {
                ˏ(o_cnw, managerTask);
            }
        }
    }

    private void ˏ(cnw o_cnw, ManagerTask managerTask) {
        d ˊ = new d().ˋ(managerTask.packageName).ˏ(managerTask.versionCode).ˊ(managerTask.flag);
        Object obj = null;
        for (a aVar : managerTask.apkInfos) {
            if (new File(aVar.ˎ).exists()) {
                obj = 1;
                ˊ.ॱ(aVar.ˎ, aVar.ˏ, aVar.ॱ);
            }
            obj = obj;
        }
        if (obj != null) {
            o_cnw.ˋ(ContentManager.getInstant().getContext(), ˊ.ˎ());
            dgh.ॱ(ContentManager.getInstant().getContext(), "990501", managerTask.packageName);
            Logger.ˎ("RecoveryPackageTask", "recovery INHERIT install:" + managerTask.packageName);
        }
    }

    private void ॱ(cnw o_cnw, ManagerTask managerTask) {
        if (((cdg) cdb.ॱ(cdg.class)).ˎ(managerTask.packageName, managerTask.versionCode)) {
            if (managerTask.apkInfos != null) {
                for (a aVar : managerTask.apkInfos) {
                    if (!(aVar == null || TextUtils.isEmpty(aVar.ˎ) || new File(aVar.ˎ).delete())) {
                        Logger.ˋ("RecoveryPackageTask", "expired task,can not find the file,delete failed:" + aVar.ॱ);
                    }
                }
            }
            Logger.ˋ("RecoveryPackageTask", "last install task is expired:" + managerTask.packageName);
            return;
        }
        d ॱ = new d().ˋ(managerTask.packageName).ˏ(managerTask.versionCode).ˊ(managerTask.flag).ॱ(dwq.ˊ);
        Object obj = null;
        for (a aVar2 : managerTask.apkInfos) {
            Object obj2;
            if (new File(aVar2.ˎ).exists()) {
                ॱ.ॱ(aVar2.ˎ, aVar2.ˏ, aVar2.ॱ);
                if (("base".equals(aVar2.ˏ) && aVar2.ॱ == 1) || aVar2.ॱ == 0) {
                    obj2 = 1;
                    obj = obj2;
                }
            }
            obj2 = obj;
            obj = obj2;
        }
        if (obj != null) {
            o_cnw.ˋ(ContentManager.getInstant().getContext(), ॱ.ˎ());
            dgh.ॱ(ContentManager.getInstant().getContext(), "990501", managerTask.packageName);
            Logger.ˎ("RecoveryPackageTask", "recovery FULL install:" + managerTask.packageName);
            return;
        }
        ˊ(managerTask);
    }

    private void ˊ(ManagerTask managerTask) {
        for (a aVar : managerTask.apkInfos) {
            if (!(TextUtils.isEmpty(aVar.ˎ) || new File(aVar.ˎ).delete())) {
                Logger.ˋ("RecoveryPackageTask", "delete failed");
            }
        }
    }
}
